//
//  VistitorTableViewController.swift
//  KitchenAssistant
//
//  Created by 陈燕璇 on 2021/3/30.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    /// 用户登录标记
    private var userLogon = false
   
    /// 访客视图
    var visitorView: VisitorView?
    
    override func loadView() {
        
        // 根据用户登录情况，决定显示的根视图
        userLogon ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
       // print(visitorView as Any)
    }
    
    /// 设置访客视图 - 让每一个`小`函数
    private func setupVisitorView() {
        // 替换根视图
        visitorView = VisitorView()
        
        view = visitorView
        
        // 添加监听方法
        visitorView?.registerButton.addTarget(self, action: #selector(self.visitorLoginViewDidRegister),for: UIControl.Event.touchUpInside)
        visitorView?.loginButton.addTarget(self, action:#selector(self.visitorLoginViewDidLogin), for: UIControl.Event.touchUpInside)
        
    }
    // MARK: - 访客视图按钮监听方法
    @objc private func visitorLoginViewDidLogin() {
        print("用户登录")
    }

    @objc private func visitorLoginViewDidRegister() {
        print("用户注册")
    }
}
